// pages/show/show.js
import baseUrl from '../../api/request'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        bgcImg: 'background-image: url("https://img0.baidu.com/it/u=2968970951,2186199366&fm=26&fmt=auto");background-size: 100% 100%;',
        background: [],
        indicatorDots: true,
        vertical: false,
        autoplay: true,
        interval: 2000,
        duration: 500,
        scrollBtns: [
            {icon: 'icon-rili',title: '每日推荐'},
            {icon: 'icon-FM_weixuanze',title: '私人FM'},
            {icon: 'icon-gedan',title: '歌单'},
            {icon: 'icon-paihangbang_paiming',title: '排行榜'},
            {icon: 'icon-zhuanji',title: '数字专辑'},
            {icon: 'icon-xingxing',title: '专注冥想'},
            {icon: 'icon-keaide',title: '歌房'},
            {icon: 'icon-youxi',title: '游戏专区'},
        ],
        recommendList: [
            {url: '',title: '文字',num: '123'}
        ],
        basicData: []
    },
    // goSearchPage() {
    //     wx.switchTab({
    //         url: '',
    //     })
    // },
    //获取轮播图数据
    getSwiperData(){
        var that = this
        let url = baseUrl.proxy +'/banner'
        wx.request({
          url: url,
          success(res){
            console.log(res);
            if(res.data.code == 200){
                that.setData({
                    background: res.data.banners
                })
                console.log(that.data);
            }
          }
        })
        
    },
    getRecommend(){
        var that = this
        let url = baseUrl.proxy +'/personalized'
        wx.request({
          url: url,
          success(res){
              var songList = res.data.result.slice(0,5)
              songList.map(item => {
                  if(item.playCount > 100000000){
                      item.playCount = (item.playCount/100000000).toFixed(2) + '亿'
                  }else if(item.playCount > 10000){
                      item.playCount = (item.playCount / 10000).toFixed(2) + '万'
                  }else{
                      item.playCount = item.playCount
                  }
              })
              that.setData({
                  recommendList: res.data.result.slice(0,5)
              })
          }
        })
    },
    getBasicSong(){
        var that = this
        var url = baseUrl.proxy+ '/personalized/newsong'
        wx.request({
          url: url,
          data: {limit:9},
          success(res){
              if(res.data.code == 200){
                that.setData({
                    basicData: res.data.result
                })
              }
          }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getSwiperData()
        this.getRecommend()
        this.getBasicSong()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})